package erp.education.server.beans.implementation.finance.master;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import erp.education.client.finance.master.FeeGroupRequest;
import erp.education.server.beans.implementation.BaseService;
import erp.education.server.beans.implementation.ResultResponse;
import erp.education.server.beans.implementation.ServiceObject;
import erp.education.server.beans.interfaces.finance.master.FeeGroupServiceI;
import erp.education.server.beans.interfaces.user.transaction.ServiceObjectI;
import erp.education.server.db.entites.finance.FeeGroup;
import erp.education.server.db.exceptions.DbExceptions;

@Component("feeGroupService")
public class FeeGroupService extends BaseService implements FeeGroupServiceI {

	@Override
	public ServiceObjectI feeGroupLoadSevice(FeeGroupRequest feeGroupRequest)
			throws DbExceptions {
		ServiceObjectI response = new ServiceObject();
		ResultResponse holder = new ResultResponse();
		List result = new ArrayList();
		result.add(feeGroupDao.getFeeGroups());

		holder.setResultList(result);
		response.setResponseObject(holder);
		return response;
	}

	@Override
	public ServiceObjectI saveUpdateFeeGroupDetails(
			FeeGroupRequest feeGroupRequest) throws DbExceptions {
		ServiceObjectI response = new ServiceObject();
		ResultResponse holder = new ResultResponse();
		List result = new ArrayList();
		FeeGroup feeGroup = null;
		try {
			feeGroup = feeGroupDao.getFeeGroup(feeGroupRequest.getGroupId());
		} catch (Exception e) {
		}
		if (null == feeGroup) {
			feeGroup = new FeeGroup();

		}
		feeGroup.setGroupCode(feeGroupRequest.getGroupCode());
		feeGroup.setGroupName(feeGroupRequest.getGroupName());
		feeGroupDao.merge(feeGroup);
		holder.setResultList(result);
		response.setResponseObject(holder);
		return response;
	}
}
